// components/quickBuy/quickBuy.js
const app = getApp();
const tmpurl = "shopItem1.png";

Component({

  /**
   * 组件的属性列表
   */
  properties: {
    isTipsShow:{ 
      type: Boolean,
      value: true
    },
    icon:{ 
      type: String,
      value: tmpurl
    },
    info:{ // 属性名
      type: String,
      value: ""
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    cloudUrl:app.globalData.cloudUrl,
    unitSelect:false,
    unitBorder:"",
    unitColor:"#000000",
    selectStr:"请选择",
    curInfo:{},
    num:1
  },
  attached: function() { 
    try{
      //console.log("attachedattachedattached");
      const obj = JSON.parse(this.data.info);
      this.setData({curInfo:obj,icon:obj.icon});
    }
    catch(e){
      console.log("报错attachedattached"+e);
    }
   
  },
  /**
   * 组件的方法列表
   */
  methods: {
    onUnitClick(e){
      var select = !this.data.unitSelect;
      var border,color,str;
      if(select){
        border = "2rpx solid rgb(51,153,255)";
        color = "rgb(51,153,255)";
        str = "已选择：" + this.data.curInfo.units[0].desc;
      }
      else{
        border = "";
        color = "rgb(0,0,0)";
        str = "请选择";
      }
      this.setData({unitSelect:select,unitBorder:border,unitColor:color,selectStr:str});
    },
    onStepChange(e){
      console.log(e);
      this.setData({num:e.detail});
    },
    onTipsViewClick(e){
      this.setData({isTipsShow:false});
      var myEventDetail = {type:"close"} // detail对象，提供给事件监听函数
      var myEventOption = {} // 触发事件的选项
      this.triggerEvent('myevent', myEventDetail, myEventOption)
    },
    onBtnClick(e){
      //Toast("请选择商品规格和属性");
      if(this.data.unitSelect){
        this.setData({isTipsShow:false});
      }
      var myEventDetail = {type:"confirm",num:this.data.num,item:this.data.curInfo,select:this.data.unitSelect} // detail对象，提供给事件监听函数
      var myEventOption = {} // 触发事件的选项
      this.triggerEvent('myevent', myEventDetail, myEventOption)
    }
  }
})